'use strict';
const db = uniCloud.database()
const collection = db.collection('user_info')
exports.main = async (event, context) => {
	let res;
	if(event.type === 'addUser'){
		res = addUser(event,context)
	}
	if(event.type === 'getUser'){
		res = selectUserByName(event,context)
	}
	if(event.type === 'getUserById'){
		res = selectUserById(event,context)
	}
	//返回数据给客户端
	return res
};

async function addUser(event,context){
	let res = await collection.add(event.userInfo)
	return res
} //新增用户

async function selectUserByName(event,context){
	let res = await collection.where({
		nickName:event.userInfo.nickName
	}).get()
	return res
} //通过用户名查询

async function selectUserById(event,context){
	let res = await collection.where({
		_id:event.user_id
	}).get()
	return res
} //通过用户id查询

